package cn.erperp.kcp.ui.home;

import android.os.Bundle;
import android.preference.Preference;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import cn.erperp.kcp.databinding.FragmentHomeBinding;
import io.netty.util.internal.StringUtil;

public class HomeFragment extends Fragment {

    private FragmentHomeBinding binding;

    private KcpIdleExampleClientPrivate kcpIdleExampleClientPrivate;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        HomeViewModel homeViewModel =
                new ViewModelProvider(this).get(HomeViewModel.class);


        kcpIdleExampleClientPrivate = new KcpIdleExampleClientPrivate();

        binding = FragmentHomeBinding.inflate(inflater, container, false);
        System.out.println("onCreateView...");
        Log.v("KcpIdleExampleClientPrivate", "onCreateView...");

        Button buttonLink = binding.buttonLocal;
        buttonLink.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("KcpIdleExampleClientPrivate", "local init() ");
                EditText ipLocal = binding.ipLocal;
                // 在这里编写按钮点击时的逻辑
                Toast.makeText(getContext(), "Button Link clicked!", Toast.LENGTH_SHORT).show();
                kcpIdleExampleClientPrivate.init(ipLocal.getText().toString());

            }
        });

        binding.buttonCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                kcpIdleExampleClientPrivate.stop();
            }
        });

        Button buttonProd = binding.buttonProd;
        buttonProd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("KcpIdleExampleClientPrivate", "prod init() ");
                EditText ip = binding.ipProd;
                // 在这里编写按钮点击时的逻辑
                Toast.makeText(getContext(), "Button Link clicked!", Toast.LENGTH_SHORT).show();
                kcpIdleExampleClientPrivate.init(ip.getText().toString());

            }
        });

        View root = binding.getRoot();
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}